var del = require('del');
var gulp = require('gulp');
var concat = require('gulp-concat');
var cleanCSS = require('gulp-clean-css');
var stripCssComments = require('gulp-strip-css-comments');
var imagemin = require('gulp-imagemin');
var babel = require('gulp-babel');

gulp.task('concat-css', function() {
  return gulp.src('./public/styles/*.css')
  	.pipe(stripCssComments())
    .pipe(concat('main.css'))
    .pipe(gulp.dest('./public/styles/'));
});

gulp.task('imagemin', function(){
  return gulp.src('./src/images/**/*')
    .pipe(imagemin())
    .pipe(gulp.dest('./src/www/images'))
})

gulp.task('min-css', function() {
  return gulp.src('./public/styles/main.css')
    .pipe(cleanCSS({compatibility: '*'}))
    .pipe(concat('main.min.css'))
    .pipe(gulp.dest('./public/styles/'));
});

// 启用server环境
gulp.task('set-server-babel-env', function() {
  return process.env.BABEL_ENV = 'server';
});

// 转化es6->es5
gulp.task('es5', ['set-server-babel-env'], function () {
  // 先清空dist
  del(['dist/**/*']);
  return gulp.src('./lib/**/*')// ES6 源码存放的路径
    .pipe(babel()) 
    .pipe(gulp.dest('./dist')); //转换成 ES5 存放的路径
});

// gulp.task('es5-single', function () {
//   return gulp.src('./server/serverRender.js')// ES6 源码存放的路径
//     .pipe(babel()) 
//     .pipe(gulp.dest('./server')); //转换成 ES5 存放的路径
// });

gulp.task('default', function() {
  // 默认
});

